package com.chris.core.socket.netty.run;

import com.chris.core.socket.netty.dto.protocol.CmdObjectProtocol;
import com.chris.core.socket.netty.dto.protocol.CustomMessageProtocol;
import com.chris.core.socket.netty.dto.SocketTypeEnum;
import com.chris.core.socket.netty.handler.CustomClientHandler;
import com.chris.core.socket.netty.util.NettyClientUtil;
import com.chris.core.socket.netty.util.NettyRunTimeUtil;
import io.netty.channel.ChannelPipeline;

import java.io.File;

/**
 * Custom socket 客户端
 * 替代NettyOjectServer
 */
public class NettyCustomClient {
    public static void main(String[] args) throws Exception {

        NettyRunTimeUtil.runTimeBreakMark="\r\n";
        NettyClientUtil service = new NettyClientUtil("127.0.0.1",10105,180,NettyRunTimeUtil.runTimeBreakMark,false, SocketTypeEnum.CustomSocket) {
            @Override
            public void AddChannelHandler(ChannelPipeline pipeline) {

                //自定义事件
                pipeline.addLast(new CustomClientHandler());
               //ß pipeline.addLast("客户端自定义接收事件",new StringClientHandler());
            }
        };

        service.Open();

        Thread.sleep(6000);

        System.out.println("发送测试内容");
      //  service.sendStrMsg("aaaa");

        CustomMessageProtocol dto = new CustomMessageProtocol();
        dto.setContent(1);
        service.sendObjMsg(dto);

       // service.sendStrMsg("bbbb");

        String msg = "你好，我是SB！";
         dto = new CustomMessageProtocol();
        dto.setContent(msg);
        service.sendObjMsg(dto);


       // service.sendStrMsg("cccc");




        dto = new CustomMessageProtocol();
        dto.setContent(2L);
        service.sendObjMsg(dto);

        dto = new CustomMessageProtocol();
        dto.setContent(3.5);
        service.sendObjMsg(dto);

        //object cmd
        dto = new CustomMessageProtocol();
        CmdObjectProtocol cmp = new CmdObjectProtocol(1,"chris");
        dto.setContentSystemCmdObject(cmp);
        service.sendObjMsg(dto);


        //---发送文件-----
       // File file = new File("./文档ppt.zip");
       // service.sendCustomFileMsg(file);
    }


}
